package com.mccrea.pattern.iterator;

import java.util.Iterator;

/**
 * @Classname BookShelfIterator
 * @Description 书架迭代器
 * @Date 2021/5/20 0020 17:30
 * @Created by Mccrea_Gao
 */
public class BookShelfIterator implements Iterator<Book> {
    private BookShelf bookShelf;

    private int index;

    public BookShelfIterator(BookShelf bookShelf) {
        this.bookShelf = bookShelf;
        this.index = 0;
    }

    @Override
    public boolean hasNext() {
        return index < bookShelf.getLength();
    }

    @Override
    public Book next() {
        Book book = bookShelf.getBookAt(index);
        index ++;
        return book;
    }
}
